﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using com.huigo.Framework.ServiceUtils;

namespace com.huigo.Admin.Web
{
    public class Tools
    {
        public static List<DropList> ParserToDropList(ParserXml parser, string id, string name)
        {
            if (parser != null && parser.RowsCount > 0)
            {
                List<DropList> dList = new List<DropList>();
                dList.Add(new DropList());
                for (int i = 0; i < parser.RowsCount; i++)
                {
                    dList.Add(new DropList(parser[id, i], parser[name, i]));
                }
                return dList;
            }
            else
                return null;
        }

        public static List<DropList> DictToDropList(Dictionary<int, string> dict)
        {
            if (dict != null && dict.Count > 0)
            {
                List<DropList> dList = new List<DropList>();
                dList.Add(new DropList());
                foreach (KeyValuePair<int, string> kvp in dict)
                {
                    dList.Add(new DropList(kvp.Key.ToString(), kvp.Value));
                }
                return dList;
            }
            else
                return null;
        }

        public static List<DropList> DictToDropList(Dictionary<string, string> dict)
        {
            if (dict != null && dict.Count > 0)
            {
                List<DropList> dList = new List<DropList>();
                dList.Add(new DropList());
                foreach (KeyValuePair<string, string> kvp in dict)
                {
                    dList.Add(new DropList(kvp.Key.ToString(), kvp.Value));
                }
                return dList;
            }
            else
                return null;
        }

        public static List<DropList> DictToRadioButtonList(Dictionary<int, string> dict)
        {
            if (dict != null && dict.Count > 0)
            {
                List<DropList> dList = new List<DropList>();
                foreach (KeyValuePair<int, string> kvp in dict)
                {
                    dList.Add(new DropList(kvp.Key.ToString(), kvp.Value));
                }
                return dList;
            }
            else
                return null;
        }
    }

    public class DropList
    {
        private string Id;

        public string id
        {
            get { return Id; }
            set { Id = value; }
        }

        private string Value;

        public string value
        {
            get { return Value; }
            set { Value = value; }
        }

        public DropList()
        {
            this.id = string.Empty;
            this.value = string.Empty;
        }

        public DropList(string id, string value)
        {
            this.id = id;
            this.value = value;
        }
    }
}
